<template>
  <el-card>
    <div slot="header">
      <h3>{{ title }}</h3>
    </div>
    <div class="page-body">
      <BtnRender :render="renderHeaderBtnsBar" />
      <el-divider />
      <el-row type="flex" justify="space-between">
        <div>
          <TextTooltip
            v-if="isAdd"
            label="图文是否必填"
            :textContent="finishedImgFlagStr"
          />
        </div>
        <BtnRender :render="renderTableBtnsBar" />
      </el-row>
      <el-divider />
      <div class="action-wrap">
        <LabelSelect
          multiple
          clearable
          size="mini"
          class="second-select"
          placeholder="批量设置售卖平台"
          label-width="130px"
          :disabled="TableInfo.isNullSelection()"
          :value.sync="salePlatSelect.value"
          :options="salePlatSelect.options"
          @change="handleBatchSetSalePlat"
        />
        <BtnRender :render="renderTableBtns_2Bar" />
      </div>
      <skus-table
        ref="tableRef"
        showSelectCol
        :tableHeight="480"
        :defaultMinWidth="100"
        :dataSource="TableInfo.list"
        :columns="TableInfo.columns"
        :loading="TableInfo.loading"
        :selectionChange="TableInfo.setSelection"
        @input-focus="inputFocusHandler"
        @input-change="inputChangeHandler"
        @handleRowChange="inputNumberChangeHandler"
      >
        <template v-slot:specAttrs="slotProps">
          <AttributePerfectPopover
            placement="left"
            :complete-status="slotProps.data.row.specAttrStatus"
            :attribute-vos="slotProps.data.row.specAttributeVos"
            @perfect="handleSetSpecAttrs(slotProps.data.index)"
            @has-perfect="handleSetSpecAttrs(slotProps.data.index)"
          />
        </template>
        <template v-slot:basicAttrs="slotProps">
          <AttributePerfectPopover
            placement="right"
            :complete-status="slotProps.data.row.notSpecAttrStatus"
            :attribute-vos="slotProps.data.row.notSpecAttributeVos"
            @perfect="handleSetBasicAttrs(slotProps.data.index)"
            @has-perfect="handleSetBasicAttrs(slotProps.data.index)"
          />
        </template>
        <template v-slot:imageStatusStr="slotProps">
          <PerfectLink
            :complete-status="slotProps.data.row.imageStatus"
            @click="handlePerfectImage(slotProps.data.index, slotProps.data.row)"
          />
        </template>
      </skus-table>
    </div>
    <!-- 关联四级类弹框 -->
    <AssociatedDialog
      dialogTitle="关联四级类"
      currentType="1"
      :notQueryClassify="false"
      :visible.sync="associateCategory.visible"
      @getSelectResults="updateCategoryInfo"
    />
    <!-- 关联品牌弹框 -->
    <SelectBrandAndSeries
      :visible.sync="associateBrand.visible"
      @update="updateBrandAndSeriesInfo"
    />
    <!-- 系列弹框 -->
    <BatchSetSeries
      :visible.sync="setSeries.visible"
      :brandUuid="setSeries.brandUuid"
      @update="updateSeriesInfo"
    />
    <!-- 材质弹框 -->
    <AssociatedDialog
      dialogTitle="批量设置材质"
      currentType="5"
      width="40%"
      :visible.sync="setMaterial.visible"
      @getSelectResults="updateMaterialInfo"
    />
    <!-- 销售区域弹框 -->
    <SalesAreaDialog
      :visible.sync="salesArea.visible"
      :cityList="salesArea.cityList"
      :selectCitys="salesArea.selectCitys"
      @getSaleAreas="updateSaleAreas"
    />
    <!-- 完善基本属性弹框 -->
    <BatchAddBasicAttrsDialog
      :visible.sync="basicAttrs.visible"
      :values-maps="basicAttrs.valuesMaps"
      :selection="basicAttrs.selection"
      @update-basic-attrs="updateBasicAttrsInfo"
    />
    <!-- 完善规格属性弹框 -->
    <BatchAddSpecAttrsDialog
      :visible.sync="specAttrs.visible"
      :values-maps="specAttrs.valuesMaps"
      :selection="specAttrs.selection"
      @update-spec-attrs="updateSpecAttrsInfo"
    />
    <!-- 图文完善弹框 -->
    <SaveLatentImageDialog
      :visible.sync="saveLatentImage.visible"
      :image-info="saveLatentImage.imageInfo"
      :record-detail-uuid="saveLatentImage.recordDetailUuid"
      :sku-info="saveLatentImage.skuInfo"
      @updateImageInfo="updateImageInfo"
      @success="loadTableList"
    />
    <!-- 选择产地弹框 -->
    <OriginalPlaceDialog
      :visible.sync="producingArea.visible"
      @getOriginalPlace="updateProducingArea"
    />
    <!-- 归类弹框 -->
    <BatchSetClassification
      :visible.sync="setClassification.visible"
      :classificationDTOS="setClassification.options"
      @update="updateClassificationInfo"
    />
  </el-card>
</template>
<script>
import BtnRender from '@/components/JSXRender/BtnRender';
import SkusTable from '@/components/skusTable';
import LabelSelect from '@/pages/commodity/components/LabelSelect';
import TextTooltip from '@/components/ShowContent/TextTooltip';
import AssociatedDialog from '../../components/AssociatedDialog';
import SalesAreaDialog from '@/components/SalesAreaDialog';
import BatchAddBasicAttrsDialog from './BatchAddBasicAttrsDialog';
import BatchAddSpecAttrsDialog from './BatchAddSpecAttrsDialog';
import AttributePerfectPopover from '../../components/AttributePerfectPopover';
import PerfectLink from '../../components/PerfectLink';
import SaveLatentImageDialog from './SaveLatentImageDialog';
import OriginalPlaceDialog from '@/components/common/dialog/originalPlaceDialog';
import SelectBrandAndSeries from '../../components/SelectBrandAndSeries';
import BatchSetSeries from '../../components/BatchSetSeries';
import BatchSetClassification from '../../components/BatchSetClassification';
import { TableInfo } from '@/utils/getUtils';
import { createExcelByExport, generateUuid, isResponseSuccess, toFixedCustomize } from '@/utils/bizUtils';
import { getListPageBtnsBar } from '@/utils/getBtnsRender';
import { getAttributeValueVosByUniqKey, getCompleteStatusStr } from '../utils';
import { COMMON_COMP_CONFIGS, IMAGE_REQUIRE_ENUMS, IMAGE_REQUIRE_LABELS } from '../constants/common';
import { COMMON_IMAGE_STATUS_ENUMS } from '@/constants/commodity';
import compRender from '@/mixins/getCompRender';
import { querySalePlatAndSaleAreasService } from '@/api/public'; // 获取售卖平台及销售区域
import {
  export4EditService,
  import4EditUrl,
  getNotSpecAttrStatusByCategoryUuidService
} from '@/api/commodity/temporaryPurchasingGoods/latentProduct';
export default {
  mixins: [compRender],
  components: {
    BtnRender,
    SkusTable,
    LabelSelect,
    TextTooltip,
    AssociatedDialog,
    SalesAreaDialog,
    BatchAddBasicAttrsDialog,
    BatchAddSpecAttrsDialog,
    AttributePerfectPopover,
    PerfectLink,
    SaveLatentImageDialog,
    OriginalPlaceDialog,
    SelectBrandAndSeries,
    BatchSetSeries,
    BatchSetClassification,
  },
  props: {
    // 页面标题
    title: {
      type: String,
      required: true
    },
    // 是否是新增页操作
    isAdd: {
      type: Boolean,
      default: false
    },
    columns: {
      type: Array,
      default: () => []
    },
    loadData: {
      type: Function,
      default: () => {}
    },
    submitData: {
      type: Function,
      default: () => {}
    },
    // 是否展示替代商品按钮
    getReplaceBtn: {
      type: Function,
      default: () => {}
    }
  },
  data () {
    return {
      TableInfo: new TableInfo({ columns: this.columns }),
      // 售卖平台下拉
      salePlatSelect: {
        value: [],
        options: []
      },
      // 关联品类
      associateCategory: { ...COMMON_COMP_CONFIGS },
      setClassification: {
        ...COMMON_COMP_CONFIGS,
        options: []
      },
      // 关联品牌
      associateBrand: { ...COMMON_COMP_CONFIGS },
      // 设置系列
      setSeries: {
        ...COMMON_COMP_CONFIGS,
        brandUuid: ''
      },
      // 设置材质
      setMaterial: { ...COMMON_COMP_CONFIGS },
      // 销售区域
      salesArea: {
        ...COMMON_COMP_CONFIGS,
        cityList: [], // 城市全量集合
        selectCitys: [], // 当前勾选城市编码集合
      },
      // 产地
      producingArea: { ...COMMON_COMP_CONFIGS },
      // 基本属性
      basicAttrs: {
        ...COMMON_COMP_CONFIGS,
        valuesMaps: {},
        selection: []
      },
      // 规格属性
      specAttrs: {
        ...COMMON_COMP_CONFIGS,
        valuesMaps: {},
        selection: []
      },
      // 图文完善
      saveLatentImage: {
        ...COMMON_COMP_CONFIGS,
        imageInfo: null,
        recordDetailUuid: '', // 线索转潜在维护图文 保存图文提交人 所需参数
        skuInfo: null, // 潜在编辑维护图文所需参数
      },
      btnLoading: {
        export: false, // 导出loading
        submit: false, // 提交loading
      },
    }
  },
  created () {
    this.loadSalePlatAndSaleAreas()
    this.updateBrandseriesRenderCol()
    this.updateClassifyRenderCol()
    this.loadTableList()
  },
  computed: {
    // 图文是否必填
    finishedImgFlagStr () {
      const finishedImgFlag = this.TableInfo.list[0]?.finishedImgFlag
      const flagStr = IMAGE_REQUIRE_LABELS[finishedImgFlag] ?? ''
      return flagStr
    }
  },
  methods: {
    // 渲染表头按钮操作栏
    renderHeaderBtnsBar (h) {
      const btnList = [
        !this.isAdd && {
          label: '返回',
          method: this.handleGoBack,
          type: 'default'
        },
        this.isAdd && this.getReplaceBtn(this.TableInfo.list),
        {
          label: '导出',
          method: this.handleExport,
          disabled: this.TableInfo.isNullList(),
          loading: this.btnLoading.export
        },
        {
          label: '导入',
          action: import4EditUrl,
          methods: { handleUploadSuccess: this.handleUploadSuccess },
          isImport: true,
          loadingFn: this.TableInfo.setLoading
        },
        this.isAdd && {
          label: '保存',
          method: this.handleSave,
          disabled: this.TableInfo.isNullList(),
          loading: this.btnLoading.submit
        },
        {
          label: '提交',
          method: this.handleSubmit,
          disabled: this.TableInfo.isNullList(),
          loading: this.btnLoading.submit
        },
      ].filter(item => item)
      return getListPageBtnsBar(h, btnList)
    },
    // 渲染按钮操作栏
    renderTableBtnsBar (h) {
      const disabled = this.TableInfo.isNullSelection()
      const btnList = [
        { label: '批量完善规格属性', method: this.handleBatchPerfectSpecAttrs, disabled },
        { label: '批量完善基本信息', method: this.handleBatchPerfectBasicInfo, disabled },
        { label: '销售区域', method: this.handleSaleArea, disabled },
        { label: '关联品类', method: this.handleAssociateCategory, disabled },
        { label: '关联品牌', method: this.handleAssociateBrand, disabled },
      ]
      return getListPageBtnsBar(h, btnList, null, 'end', { type: 'default' })
    },
    // 渲染按钮操作栏2
    renderTableBtns_2Bar (h) {
      const disabled = this.TableInfo.isNullSelection()
      const btnList = [
        { label: '一键勾选相同品类', method: this.handleCheckSameCategory, disabled },
        { label: '归类', method: this.handleClassification, disabled },
        { label: '一键勾选相同品牌', method: this.handleCheckSameBrand, disabled },
        { label: '系列', method: this.handleSeries, disabled },
        { label: '材质', method: this.handleMaterial, disabled },
      ]
      return getListPageBtnsBar(h, btnList, null, 'end', { type: 'default' })
    },
    // 返回
    handleGoBack () {
      this.$emit('go-back')
    },
    // 批量完善规格属性
    handleBatchPerfectSpecAttrs () {
      const specAttributeVosMaps = getAttributeValueVosByUniqKey(this.TableInfo.selection, 'specAttributeVos')
      this.specAttrs.valuesMaps = specAttributeVosMaps
      this.specAttrs.selection = this.TableInfo.selection
      this.specAttrs.open()
    },
    // 批量完善基本信息
    handleBatchPerfectBasicInfo () {
      const notSpecAttributeVosMaps = getAttributeValueVosByUniqKey(this.TableInfo.selection, 'notSpecAttributeVos')
      this.basicAttrs.valuesMaps = notSpecAttributeVosMaps
      this.basicAttrs.selection = this.TableInfo.selection
      this.basicAttrs.open()
    },
    // 销售区域
    handleSaleArea () {
      this.salesArea.open()
    },
    // 关联品类
    handleAssociateCategory () {
      this.associateCategory.open()
    },
    // 关联品牌
    handleAssociateBrand () {
      this.associateBrand.open()
    },
    // 系列
    handleSeries () {
      const brandUuid = this.TableInfo.selection[0].brandUuid
      const isAllSameBrand = this.TableInfo.selection.every(item => item.brandUuid == brandUuid)
      if (!isAllSameBrand) return this.$message.warning('请勾选相同品牌的商品进行系列设置')
      this.setSeries.brandUuid = brandUuid
      this.setSeries.open()
    },
    // 归类
    handleClassification () {
      const categoryUuid = this.TableInfo.selection[0].categoryUuid
      const isAllSameBrand = this.TableInfo.selection.every(item => item.categoryUuid == categoryUuid)
      if (!isAllSameBrand) return this.$message.warning('请勾选相同品类的商品进行系列设置')
      this.setClassification.options = this.TableInfo.selection[0]?.classificationDTOS ?? []
      this.setClassification.open()
    },
    // 一键勾选相同品牌
    handleCheckSameBrand () {
      const brandUuid = this.TableInfo.selection[0].brandUuid
      const isAllSameBrand = this.TableInfo.selection.every(item => item.brandUuid == brandUuid)
      if (!isAllSameBrand) return this.$message.warning('不支持勾选多个品牌进行设置')
      this.TableInfo.list.forEach(item => {
        if (item.brandUuid != brandUuid) return
        this.$nextTick(() => {
          this.$refs.tableRef.$refs.plTable.$refs.singleTable.toggleRowSelection(item, true)
        })
      })
    },
    // 一键勾选相同品类
    async handleCheckSameCategory () {
      const categoryUuid = this.TableInfo.selection[0].categoryUuid
      const isAllSameCategory = this.TableInfo.selection.every(item => item.categoryUuid == categoryUuid)
      if (!isAllSameCategory) return this.$message.warning('不支持勾选多个品类进行设置')
      this.TableInfo.list.forEach(item => {
        if (item.categoryUuid != categoryUuid) return
        this.$nextTick(() => {
          this.$refs.tableRef.$refs.plTable.$refs.singleTable.toggleRowSelection(item, true)
        })
      })
    },
    // 材质
    handleMaterial () {
      this.setMaterial.open()
    },
    // 保存
    handleSave () {
      const loadingFn = state => { this.btnLoading.submit = state }
      const isSubmit = false
      this.submitData(this.TableInfo, loadingFn, isSubmit)
    },
    // 提交
    async handleSubmit () {
      const loadingFn = state => { this.btnLoading.submit = state }
      const isSubmit = true
      this.submitData(this.TableInfo, loadingFn, isSubmit)
    },
    // 表格关联品类
    handleTableAssociateCategory (index) {
      this.associateCategory.open(index)
    },
    // 表格关联品牌
    handleTableAssociateBrand (index) {
      this.associateBrand.open(index)
    },
    // 表格销售区域
    handleTableSaleArea (index, row) {
      this.salesArea.open(index)
      this.salesArea.selectCitys = row.saleAreas.split(',')
    },
    // 表格产地
    handleTableProducing (index) {
      this.producingArea.open(index)
    },
    // 批量设置售卖平台
    handleBatchSetSalePlat () {
      this.batchUpdateValByTableKey({ salePlatCodes: this.salePlatSelect.value })
    },
    // 导出
    async handleExport () {
      const uuid = generateUuid()
      const data = {
        uuid,
        potentials: this.TableInfo.list
      }
      const loadingFn = state => { this.btnLoading.export = state }
      const res = await export4EditService(data, loadingFn)
      createExcelByExport({ excelTitle: `${this.title}_${uuid}`, res })
    },
    // 导入成功
    handleUploadSuccess (res) {
      if (isResponseSuccess(res)) {
        this.updateClassifyRenderCol()
        this.TableInfo.setList(res.retData)
      }
    },
    // 完善规格属性
    handleSetSpecAttrs (index) {
      const selection = this.getVirtualSelection(index)
      const specAttributeVosMaps = getAttributeValueVosByUniqKey(selection, 'specAttributeVos')
      this.specAttrs.valuesMaps = specAttributeVosMaps
      this.specAttrs.selection = selection
      this.specAttrs.open(index)
    },
    // 完善基本属性
    handleSetBasicAttrs (index) {
      const selection = this.getVirtualSelection(index)
      const notSpecAttributeVosMaps = getAttributeValueVosByUniqKey(selection, 'notSpecAttributeVos')
      this.basicAttrs.valuesMaps = notSpecAttributeVosMaps
      this.basicAttrs.selection = selection
      this.basicAttrs.open(index)
    },
    // 完善图文信息
    handlePerfectImage (index, row) {
      const skuInfo = {
        skuId: row.uuid,
        skuNo: row.skuNo
      }
      this.saveLatentImage.imageInfo = row.tempSkuImageVo
      this.saveLatentImage.recordDetailUuid = row.recordDetailUuid
      this.saveLatentImage.skuInfo = this.isAdd ? null : skuInfo
      this.saveLatentImage.open(index)
    },
    // 输入框change事件
    inputChangeHandler ({ row, val, prop }) {
      if (prop == 'saleMin') this.changeSaleMin(row, val)
    },
    // 数值输入框change事件
    inputNumberChangeHandler (row, val, prop) {
      if (prop == 'decimalPlaces') this.changeDecimalPlaces(row, val)
    },
    // 输入框失焦事件
    inputFocusHandler ({ prop, index, row, val }) {
      const HandlerMaps = {
        'categoryName': this.handleTableAssociateCategory,
        'brandName': this.handleTableAssociateBrand,
        'saleAreaStr': this.handleTableSaleArea,
        'producingAreaName': this.handleTableProducing,
      }
      const callback = HandlerMaps[prop] ?? (() => {})
      callback(index, row, val)
    },
    // 最小起售量变更
    changeSaleMin (row, val) {
      let curVal = val.replace(/[^0-9.]/g, '')
      if (curVal < 0) curVal = 0
      row.saleMin = toFixedCustomize(curVal, 10 ** row.decimalPlaces)
    },
    // 数量小数位变更
    changeDecimalPlaces (row, val) {
      const defaultSaleMin = val == 0 ? 0 : (10 ** -val)
      row.saleMin = defaultSaleMin
    },
    // 加载销售区域集合和售卖平台集合
    async loadSalePlatAndSaleAreas () {
      const res = await querySalePlatAndSaleAreasService({})
      this.updateSaleAreasInfo(res?.retData?.saleAreaList ?? [])
      this.updateSalePlatInfo(res?.retData?.salePlatList ?? [])
    },
    // 加载列表数据
    async loadTableList () {
      const res = await this.loadData(this.TableInfo.setLoading)
      this.TableInfo.setList(res?.retData)
    },
    // 获取勾选集合或当前点击行填充的集合selection
    getVirtualSelection (index) {
      const selection = (index != null && index > -1)
        ? [this.TableInfo.list[index]]
        : this.TableInfo.selection
      return selection
    },
    // 更新售卖平台信息
    updateSalePlatInfo (salePlatList) {
      // 售卖平台下拉集合
      this.salePlatSelect.options = salePlatList.map(item => ({
        value: item.salePlatCode,
        label: item.salePlatName
      }))
      const index = this.TableInfo.columns.findIndex(item => item.key == 'salePlatCodes')
      if (index == -1) return
      this.TableInfo.columns[index].options = this.salePlatSelect.options
    },
    // 更新品类信息
    async updateCategoryInfo (info) {
      const data = { categoryUuid: info?.categoryUuid }
      const res = await getNotSpecAttrStatusByCategoryUuidService(data, this.TableInfo.setLoading)
      this.clearAttributeVosByChangeCategory(res?.retData?.notSpecAttrStatus)
      this.batchUpdateValByTableKey(info, this.associateCategory.curIndex)
      this.resetAllCurIndex()
    },
    // 更新品牌系列信息
    updateBrandAndSeriesInfo (info) {
      this.batchUpdateValByTableKey(info, this.associateBrand.curIndex)
      this.resetAllCurIndex()
    },
    // 更新系列信息
    updateSeriesInfo (info) {
      this.batchUpdateValByTableKey(info, this.setSeries.curIndex)
      this.resetAllCurIndex()
    },
    // 更新归类信息
    updateClassificationInfo (info) {
      this.batchUpdateValByTableKey(info, this.setClassification.curIndex)
      this.resetAllCurIndex()
    },
    // 更新材质信息
    updateMaterialInfo (info) {
      this.batchUpdateValByTableKey(info, this.setMaterial.curIndex)
      this.resetAllCurIndex()
    },
    // 更新销售区域信息
    updateSaleAreas (checkedCodes) {
      const saleAreaStr = this.salesArea.cityList
        .filter(item => checkedCodes.includes(item.areaCode))
        .map(item => item.shortName)
        .join(',')
      const saleAreas = (checkedCodes ?? []).join(',')
      const info = { saleAreaStr, saleAreas }
      this.batchUpdateValByTableKey(info, this.salesArea.curIndex)
      this.resetAllCurIndex()
    },
    // 更新产地信息
    updateProducingArea (info) {
      this.batchUpdateValByTableKey(info, this.producingArea.curIndex)
      this.resetAllCurIndex()
    },
    // 更新基本属性信息
    updateBasicAttrsInfo (attributeVosGroups) {
      this.batchUpdateAttributeVos(attributeVosGroups, ['notSpecAttributeVos', 'notSpecAttrStatus', 'notSpecAttrStatusStr'])
      this.resetAllCurIndex()
    },
    // 更新规格属性信息
    updateSpecAttrsInfo (attributeVosGroups) {
      this.batchUpdateAttributeVos(attributeVosGroups, ['specAttributeVos', 'specAttrStatus', 'specAttrStatusStr'])
      this.resetAllCurIndex()
    },
    // 更新图文信息
    updateImageInfo (info) {
      this.batchUpdateValByTableKey(info, this.saveLatentImage.curIndex)
      this.resetAllCurIndex()
    },
    // 更新销售区域信息
    updateSaleAreasInfo (saleAreaList) {
      this.salesArea.cityList = saleAreaList // 销售区域集合
      this.resetAllCurIndex()
    },
    // 更新品牌系列表列render
    updateBrandseriesRenderCol () {
      const curKey = 'seriesUuid'
      const index = this.TableInfo.columns.findIndex(item => item.key == curKey)
      if (index == -1) return
      this.TableInfo.columns[index] = {
        ...this.TableInfo.columns[index],
        render: (h, { row }) => this.getElSelect(h, {
          row,
          key: curKey,
          size: 'mini',
          options: row?.seriesInfoVos ?? [],
          optionValKey: 'seriesUuid',
          optionLabelKey: 'series'
        })
      }
    },
    // 更新归类表列render
    updateClassifyRenderCol () {
      const index = this.columns.findIndex(item => item.key == 'classificationName')
      if (index == -1) return
      this.TableInfo.columns[index] = {
        ...this.TableInfo.columns[index],
        render: (h, { row, index }) => {
          const options = row.classificationDTOS ?? []
          return options.length <= 1
            ? getClassifySpanRender(h, { row })
            : getClassifySelectRender(h, { row, index })
        }
      }
      // 获取归类文本展示render
      const getClassifySpanRender = (h, { row }) => <span>{row.classificationName}</span>
      // 获取归类下拉框render
      const getClassifySelectRender = (h, { row, index }) => this.getElSelect(h, {
        row,
        key: 'classificationUuid',
        size: 'mini',
        options: row?.classificationDTOS ?? [],
        optionValKey: 'uuid',
        optionLabelKey: 'classificationName',
        changeRunFn: selectVo => {
          const options = row?.classificationDTOS ?? []
          const classifyVo = options.find(item => item.uuid == selectVo.val) ?? {}
          const updateVo = {
            classificationUuid: classifyVo?.uuid,
            ..._.pick(classifyVo, ['classificationName', 'taxCateName', 'taxCateNo', 'taxRate'])
          }
          this.batchUpdateValByTableKey(updateVo, index)
        }
      })
    },
    // 批量更新表格对应属性值
    batchUpdateValByTableKey (values, index) {
      const selection = this.getVirtualSelection(index)
      this.TableInfo.list.forEach((row, tIndex) => {
        const fIndex = selection.findIndex(item => item.skuNo == row.skuNo)
        if (fIndex == -1) return
        for (const key in values) {
          this.$set(this.TableInfo.list[tIndex], key, values[key])
        }
      })
    },
    // 批量更新属性信息 attributeVosGroups - 各SKU对应属性值分组的对象 attributeVosKey - 属性字段（基本属性或规格属性）
    batchUpdateAttributeVos (attributeVosGroups, attrParamKeys) {
      const getUpdateList = dataList => dataList.map(item => {
        if (!attributeVosGroups[item.skuNo]) return item
        const attributeVosGroupItem = attributeVosGroups[item.skuNo] ?? []
        const updateItem = {
          ...item,
          [attrParamKeys[0]]: attributeVosGroupItem,
          [attrParamKeys[1]]: COMMON_IMAGE_STATUS_ENUMS.Completed,
          [attrParamKeys[2]]: getCompleteStatusStr(COMMON_IMAGE_STATUS_ENUMS.Completed)
        }
        return updateItem
      })
      this.TableInfo.setList(getUpdateList(this.TableInfo.list))
      if (this.TableInfo.isNullSelection()) return
      this.TableInfo.setSelection(getUpdateList(this.TableInfo.selection))
    },
    // 清空属性相关信息 - 品类变更
    clearAttributeVosByChangeCategory (notSpecAttrStatus) {
      this.$message.info('品类变更，对应属性信息已清空')
      const selection = this.getVirtualSelection(this.associateCategory.curIndex)
      selection.forEach(item => {
        const index = this.TableInfo.list.findIndex(row => item.skuNo == row.skuNo)
        if (index == -1) return
        this.TableInfo.list[index].notSpecAttrStatus = notSpecAttrStatus ?? COMMON_IMAGE_STATUS_ENUMS.Incompleted
        this.TableInfo.list[index].specAttrStatus = COMMON_IMAGE_STATUS_ENUMS.Incompleted
        this.TableInfo.list[index].notSpecAttributeVos = []
        this.TableInfo.list[index].specAttributeVos = []
      })
    },
    // 重置所有弹窗对应行下标index
    resetAllCurIndex () {
      const dialogKeys = [
        'associateCategory',
        'associateBrand',
        'setMaterial',
        'setSeries',
        'salesArea',
        'producingArea',
        'basicAttrs',
        'specAttrs',
        'saveLatentImage',
      ]
      dialogKeys.forEach(key => {
        this[key].resetIndex()
      })
    },
  }
}
</script>
<style lang="less" scoped>
.el-divider--horizontal {
  margin: 12px 0;
}
.action-wrap {
  display: flex;
  align-items: center;
  justify-content: end;
  .second-select {
    margin: 0 10px;
  }
}
/deep/ .el-link--inner {
  font-size: 12px;
}
/deep/ .el-input-number {
  width: 80%;
}
</style>
